var user_messages;
var show_um;
var umb;	//user_messages_boxes
var umb_shown = true;
var debug;

function check_umb_shown()
{
	var shown = false;
	umb.each(function(){
		if ($(this).css('display')=='block'){shown=true;return}
	})
	umb_shown = shown;
}

$(document).ready(function() {
	user_messages = $('#user-messages');
	show_um = $('.show', user_messages);
	
	umb = $('.infoBox, .alertBox, .errorBox', user_messages);
	debug = $('.debugBox', user_messages).dblclick(function(){$(this).fadeOut('slow');});
	if (umb.length > 0)
	{
		setTimeout(function(){
				umb.fadeOut('slow');
				umb_shown = false;
			}, umb.length * 2000
		);
		show_um.show().click(function(){
			if (umb_shown) umb.fadeOut('slow');
			else 
			{
				umb.fadeIn('slow');
				debug.fadeIn('slow');
			}
			umb_shown = !umb_shown;
		});
		umb.click(function(){$(this).fadeOut('slow', check_umb_shown);});
	}
});